<template>
  <div id="app">
    <!-- 顶部导航栏：登录/注册/404等页面不显示 -->
    <TheHeader v-if="!hideHeaderRoutes.includes(route.name)" />
    
    <!-- 主要内容区域 -->
    <main class="main-content">
      <router-view />
    </main>
  </div>
</template>

<script setup>
import { onBeforeMount, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import TheHeader from '@/components/layout/TheHeader.vue'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()
const route = useRoute()

// 需要隐藏导航栏的路由名
const hideHeaderRoutes = ['Login', 'Register', 'ForgotPassword', 'NotFound']

// 应用初始化 - 在组件挂载前执行
onBeforeMount(async () => {
  console.log('🔄 开始初始化用户状态...')
  // 检查认证状态
  await userStore.checkAuth()
  console.log('用户认证状态:', userStore.isAuthenticated)
  console.log('用户信息:', userStore.user)
  console.log('用户token:', !!userStore.token)
  console.log('✅ 用户状态初始化完成')
})

// 组件挂载后的处理
onMounted(() => {
  console.log('✅ 用户端App组件已挂载')
})
</script>

<style>
/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #f5f5f5;
  color: #333;
}

#app {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding-top: 64px; /* 为顶部导航栏留出空间 */
}

/* 应用加载状态 */
.app-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-content {
  text-align: center;
  color: white;
}

.loading-icon {
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.loading-content p {
  font-size: 16px;
  font-weight: 500;
}

/* 移动端适配 */
@media screen and (max-width: 768px) {
  html {
    font-size: 16px;
  }
  
  .main-content {
    padding-top: 60px; /* 移动端稍微减少顶部间距 */
  }
}

/* 链接样式 */
a {
  text-decoration: none;
  color: inherit;
}
</style>